package dasregistry.utils;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.biojava.services.das.registry.ConfigBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MachineInfo {

	private ClassPathXmlApplicationContext context;
	private ConfigBean config;

	public MachineInfo() {
		context = new ClassPathXmlApplicationContext("config_dasregistry.xml");

		config = (ConfigBean) context.getBean("configBean");
	}

	public boolean isMachineForJob(String jobName) {
		String computerName = "";
		try {
			computerName = InetAddress.getLocalHost().getHostName();
			System.out.println("computer name="+computerName);
		} catch (UnknownHostException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String computerForIndexing = config.getComputerToDoIndexing();
		System.out.println("computer for "+jobName + computerForIndexing);
		// mib21789i
		if (computerName.equals(computerForIndexing)){
			System.out.println("computer is the required one so that we don't run it twice");
			return true;
		}
			
		return false;
	}

}
